<?
//帮市场部统计KPI的时候用的  查询票-景区-省市
if(!an_verify($_POST))
    exit('error');
require("/var/www/html/new/conf/le.je");
$le=new go_sql();
$le->connect();
switch ($_POST['ty']) {
	case 'tid':
        $sql = "select landid,id from uu_jq_ticket where id in({$_POST['tid']})";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[$row['id']] = $row['landid'];
            $lid .= $row['landid'].',';
        }
        $lid = rtrim($lid,',');
        $sql = "select id,areacode,title,jtype,p_type from uu_land where id in($lid)";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            /*
            foreach($r as $k => $v){
                if($v == $row['id']){
                    $n_u[$k] = array(//new uu_area
                        'areacode'=>$row['areacode'],
                        'title'=>$row['title'],
                        'lid'=>$row['id'],
                        'jtype'=>$row['jtype'],
                        'p_type'=>$row['p_type']
                    );
                }
            }
            */
            $land[$row['id']] = $row;
        }
//        exit(json_encode($n_u));
        echo json_encode(array('tid'=>$r,'land'=>$land));
		break;
    case 'aid':
        $sql = "select com_type,fid from pft_member_extinfo where fid in({$_POST['aid']})";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $com_type[$row['fid']] = $row['com_type'];
        }
        $sql = "select dname,id,creattime from pft_member where id in({$_POST['aid']})";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[$row['id']] =array(
                'dname'    => $row['dname'],
                'com_type' => $com_type[$row['id']],
                'creattime'=> $row['creattime'],
            );
        }
        echo json_encode($r);
        break;
    case 'tid_aid':
        if($_POST['tid']!='') $where = " and id in ({$_POST['tid']})";
        $sql = "select id,apply_did from uu_jq_ticket where 0=0 $where";
//        echo $sql;exit;
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[$row['id']] = $row['apply_did'];
        }
        echo json_encode($r);
        break;
    case 'get_qiandan':
        $sql = "select id,salesID from pft_member where salesID!=0";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[$row['id']] = $row['salesID'];
        }
        echo json_encode($r);
        break;
    case 'get_kefu':
        $sql = "select id,kefuID from pft_member where kefuID!=0";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[$row['kefuID']][] = $row['id'];
        }
        echo json_encode($r);
        break;
    case 'terminal':
        //返回的是 景区id=>主景区id
        $sql = "select preSalerID,dstatus,nowSalerID from pft_terminal_share";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            if($row['dstatus']==1){
                $r[$row['nowSalerID']]['major'] = $row['preSalerID'];
            }
            $r[$row['nowSalerID']]['else'][]= $row['preSalerID'];
            $salerid .=  $row['preSalerID'].',';
        }
        $salerid = rtrim($salerid,',');
        $sql = "select id,salerid,title from uu_land where salerid in($salerid)";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $land[$row['salerid']] = $row;
        }
        foreach($r as $val){
            foreach($val['else'] as $v){
                $return[$land[$v]] = $land[$val['major']];
            }
        }
        echo json_encode($return);
        break;
    case 'wx_openid':
        $sql = "select fid from uu_wx_member_pft where fromusername={$_POST['openid']}";
	default:
		# code...
		break;
}
$GLOBALS['le']->close();
exit;

function an_verify($query){
    define('SEC_KEY','0393156885586815305050516493889730425518949732797083380078766300585');
    return md5($query['time'].SEC_KEY)==$query['token'];
}
?>
